#include "SceneNode.h"
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with main.c; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

 
SceneNode::SceneNode( )
{
	_parent = NULL;
}

SceneNode::~SceneNode( )
{
	cout <<"_~SceneNode()_"<<endl;
	for(list<SceneNode*>::iterator it = _nodes.begin();it != _nodes.end();it++)
		delete (*it);	
}


void SceneNode::AddChildNode ( SceneNode* child )
{
	// prüfen ob übergebene objekt nicht null und es noch kein parent obj gesetzt hat
	if( child != NULL && !child->hasParent() )
	{
		_nodes.push_back(child);
	}
}

void SceneNode::SetParent( SceneNode* parent )
{
	if( parent != NULL )
		_parent = parent;
}

SceneNode* SceneNode::GetParent( ) const
{
	return _parent;
}


bool SceneNode::hasParent()
{
	return ( _parent != NULL );
}

list<SceneNode*>* SceneNode::getChildNodes()
{
	return &_nodes;
}

// render alle untergeordneten child objekte
void SceneNode::RenderChildObjects()
{
	for(list<SceneNode*>::iterator it = _nodes.begin();it != _nodes.end();it++)
	{
		(*it)->RenderObject();
	}
}

long SceneNode::getPolygonNumRecursive()
{
	long count = this->getPolygonNum();
	for( list<SceneNode*>::iterator it = _nodes.begin();it != _nodes.end();it++ )
		count += (*it)->getPolygonNumRecursive();		

	return count;
}

long SceneNode::getPolygonNum()
{
	return 0;
}


